class SessionController < ApplicationController
  include SimpleCaptcha::ControllerHelpers
  
  layout "layout"
  
  def new
  end
  
  def create
    if simple_captcha_valid?
      session[:user_id] = nil
      user = User.authenticate(params[:name], params[:password])
      if user
        session[:user_id] = user.id
        flash[:notice] = "Login successfully"
        redirect_to admin_index_url
      else
        flash[:notice] = "Invalid user/password combination"
        redirect_to login_url
      end
    else
      flash[:notice] = 'Security Check is invalid !'
      render :action => :new
    end
  end
  
  def destroy
    session[:user_id] = nil
    flash[:notice] = "Login out successfully"
    redirect_to new_session_url
  end
  
  def show_captcha
  end
end
